package main

import (
	"bytes"
	"fmt"
	"io"
	"net/http"
)

func main() {
	// 创建请求体
	json_data := `{"name": "tom", "age": 18}`
	// 将json放入到缓冲区
	body := bytes.NewBuffer([]byte(json_data))
	fmt.Println(body)
	// 发送POST请求，必须要指定传递的数据类型和数据
	resp, err := http.Post("https://www.httpbin.org/post", "application/json", body)
	if err != nil {
		panic(err)
	}
	// fmt.Println(resp)
	fmt.Println("响应状态码：", resp.StatusCode)
	for key, value := range resp.Header {
		fmt.Println(key, ":", value)
	}
	data, err := io.ReadAll(resp.Body)
	if err != nil {
		panic(err)
	}
	fmt.Println("响应体：", string(data))
}
